using System;
using UnityEngine;

[Serializable]
public class PartMarket : MonoBehaviour
{
	[HideInInspector]
	public bool allowed;

	public AudioClip clip;

	public GameObject test;

	public RaycastHit hit;

	public GameObject bg;

	public int exp;

	public GameObject buypart;

	public expcost cost;

	public expcost cost2;

	public buypart buy;

	public GameObject NEE;

	public GameObject selected;

	public Vector2 pos;

	public Camera mainCamera;

	public void Update()
	{
		if (Input.GetMouseButtonDown(0))
		{
			pos = UnityEngine.Input.mousePosition;
		}
		if (!allowed || !Input.GetMouseButtonUp(0))
		{
			return;
		}
		Vector3 mousePosition = UnityEngine.Input.mousePosition;
		if (mousePosition.x / pos.x <= 0.95f)
		{
			return;
		}
		Vector3 mousePosition2 = UnityEngine.Input.mousePosition;
		if (mousePosition2.x / pos.x >= 1.05f)
		{
			return;
		}
		Vector3 mousePosition3 = UnityEngine.Input.mousePosition;
		if (!(mousePosition3.y / pos.y <= 0.95f))
		{
			Vector3 mousePosition4 = UnityEngine.Input.mousePosition;
			if (!(mousePosition4.x / pos.x >= 1.05f) && Physics.Raycast(mainCamera.ScreenPointToRay(UnityEngine.Input.mousePosition), out hit, 100f) && hit.collider.name != "parts" && hit.collider.name != "buttonblocker")
			{
				AudioSource.PlayClipAtPoint(clip, Camera.main.transform.position);
				check();
			}
		}
	}

	public Camera FindCamera()
	{
		return (!GetComponent<Camera>()) ? Camera.main : GetComponent<Camera>();
	}

	public void check()
	{
		exp = PlayerPrefs.GetInt("Exp");
		buy buy = buypart.GetComponent("buy") as buy;
		MarketParts marketParts = (MarketParts)hit.collider.GetComponent(typeof(MarketParts));
		if (!marketParts)
		{
			return;
		}
		if (PlayerPrefs.GetInt(marketParts.partID) == 0)
		{
			cost.exp = marketParts.partPrice;
			if (exp < marketParts.partPrice)
			{
				NEE.SetActiveRecursively(state: true);
				cost2.exp = marketParts.partPrice;
			}
			else
			{
				buy.freeze();
				this.buy.exp = marketParts.partPrice;
				buypart.SetActiveRecursively(state: true);
				this.buy.currentpart = marketParts.partID;
			}
		}
		if (hit.collider.name.Contains("Cylinder"))
		{
			string text = marketParts.partID.Substring(3);
			if (PlayerPrefs.GetInt("RiC" + text) == 1)
			{
				PlayerPrefs.SetInt("RCord", int.Parse(text));
				UnityEngine.Object.Instantiate(selected);
			}
		}
	}

	public void Main()
	{
	}
}
